MKRULE=CRule.mk

if [ -f "$MKRULE" ]
then
rm $MKRULE
fi
touch $MKRULE

echo "OBJ_CRULE=\\" >> $MKRULE
echo "	\$(OBJDIR)rules.\$(OBJEXT)\\" >> $MKRULE
echo "	\$(OBJDIR)rule_lib.\$(OBJEXT)\\" >> $MKRULE
echo "	\$(OBJDIR)rule_regedit.\$(OBJEXT)\\" >> $MKRULE

DIR=../src/rules
DIRS=$(find $DIR -type d)

for dir in $DIRS
do
	name=$(echo ${dir##*/})
	test=$(echo $name | grep -rE '^C[0-9]+\.[0-9]+\.[0-9]+$|^COX[0-9]{4}$')
	if [ "$test" != "" ]
	then 
		echo "	\$(OBJDIR)$test.\$(OBJEXT)\\" >> $MKRULE
	fi
done

echo "" >> $MKRULE
echo "\$(OBJDIR)rules.\$(OBJEXT):\$(SRCDIR)rules/rules.c" >> $MKRULE
echo "	\$(CC) \$(CFLAG) -o\$(OBJDIR)rules.\$(OBJEXT) \$(SRCDIR)rules/rules.c" >> $MKRULE
echo "" >> $MKRULE
echo "\$(OBJDIR)rule_lib.\$(OBJEXT):\$(SRCDIR)rules/rule_lib.c" >> $MKRULE
echo "	\$(CC) \$(CFLAG) -o\$(OBJDIR)rule_lib.\$(OBJEXT) \$(SRCDIR)rules/rule_lib.c" >> $MKRULE
echo "" >> $MKRULE
echo "\$(OBJDIR)rule_regedit.\$(OBJEXT):\$(SRCDIR)rules/rule_regedit.c" >> $MKRULE
echo "	\$(CC) \$(CFLAG) -o\$(OBJDIR)rule_regedit.\$(OBJEXT) \$(SRCDIR)rules/rule_regedit.c" >> $MKRULE

for dir in $DIRS
do
	name=$(echo ${dir##*/})
	test=$(echo $name | grep -rE '^C[0-9]+\.[0-9]+\.[0-9]+$|^COX[0-9]{4}$')
	if [ "$test" != "" ]
	then 
		echo "" >> $MKRULE
		echo "\$(OBJDIR)$test.\$(OBJEXT):\$(SRCDIR)rules/$test/$test.c" >> $MKRULE
		echo "	\$(CC) \$(CFLAG) -o\$(OBJDIR)$test.\$(OBJEXT) \$(SRCDIR)rules/$test/$test.c" >> $MKRULE
	fi
done
